﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Monopoly
{

	public class Player
	{

		#region Constructors
		public Player(string t_name)
		{
			name = t_name;
			turn = false;
		}


		public Player(string t_name, Color t_color)
		{
			name = t_name;
			color = t_color;
			turn = false;
		}
		#endregion

		internal int TotalMoney()
		{
			//Returns the toal ammont of money.
			return (one * 1) + (five * 5) + (ten * 10) + (twenty * 20) + (fifty * 50) + (hunderd * 100) + (fivehunderd * 500);
		}

		internal bool pay(int value)
		{
			//Function to pay, and keep the money at the right level.
			//if return value is treu then there is enough money, if the return value is false than there is to little money.
			if (value > TotalMoney())
			{
				return false;
			}
			while (value != 0)
			{
				if ((value - 500 > 0) && (fivehunderd != 0))
				{
					while ((value - 500 > 0) && (fivehunderd > 0))
					{
						value = value - 500;
						fivehunderd--;
					}
				}
				else if ((value - 100 > 0) && (hunderd != 0))
				{
					while ((value - 100 > 0) && (hunderd > 0))
					{
						value = value - 100;
						hunderd--;
					}
				}
				else if ((value - 50 > 0) && (fifty != 0))
				{
					while ((value - 50 > 0) && (fifty > 0))
					{
						value = value - 50;
						fifty--;
					}
				}
				else if ((value - 20 > 0) && (twenty != 0))
				{
					while ((value - 20 > 0) && (fifty > 0))
					{
						value = value - 20;
						twenty--;
					}
				}
				else if ((value - 10 > 0) && (ten != 0))
				{
					while ((value - 10 > 0) && (ten > 0))
					{
						value = value - 10;
						ten--;
					}
				}
				else if ((value - 5 > 0) && (five != 0))
				{
					while ((value - 5 > 0) && (five > 0))
					{
						value = value - 5;
						five--;
					}
				}
				else if ((value - 1 > 0) && (one != 0))
				{
					while ((value - 1 > 0) && (one != 0))
					{
						value = value - 1;
						one--;
					}
				}
			}
			return true;
		}

		internal void earn_money(int value)
		{
			//Function to earn money, and keep the money at the right level.
			if ((value - 500 > 0))
			{
				while ((value - 500 > 0))
				{
					value = value - 500;
					fivehunderd++;
				}
			}
			else if ((value - 100 > 0))
			{
				while ((value - 100 > 0))
				{
					value = value - 100;
					hunderd++;
				}
			}
			else if ((value - 50 > 0))
			{
				while ((value - 50 > 0))
				{
					value = value - 50;
					fifty++;
				}
			}
			else if ((value - 20 > 0))
			{
				while ((value - 20 > 0))
				{
					value = value - 20;
					twenty++;
				}
			}
			else if ((value - 10 > 0))
			{
				while ((value - 10 > 0))
				{
					value = value - 10;
					ten++;
				}
			}
			else if ((value - 5 > 0))
			{
				while ((value - 5 > 0))
				{
					value = value - 5;
					five++;
				}
			}
			else if ((value - 1 > 0))
			{
				while ((value - 1 > 0))
				{
					value = value - 1;
					one++;
				}
			}
		}

		internal bool ThrowDice(out int dice1, out int dice2)
		{
			//randomly generates two throws between 1 and 6 and the sum of these two will be returned.
			Random random = new Random();
			dice1 = random.Next(1, 6);
			dice2 = random.Next(1, 6);
			return dice1 == dice2;
		}


        private string name;
        private int place;
		private bool turn;
		private int one;
		private int five;
		private int ten;
		private int twenty;
		private int fifty;
		private int hunderd;
		private int fivehunderd;
		private Color color;
		private int position;
		private bool isInJail;
		private int jailDiceThrows;
		private bool freeJailKans;
		private bool freeJailAlgemeenFonds;


		#region Properties

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public int Place
        {
            get { return place; }
            set { place = value; }
        }

		public bool FreeJailKans
		{
			get { return freeJailKans; }
			set { freeJailKans = value; }
		}

		public bool FreeJailAlgemeenFonds
		{
			get { return freeJailAlgemeenFonds; }
			set { freeJailAlgemeenFonds = value; }
		}
		public int JailDiceThrows
		{
			get { return jailDiceThrows; }
			set { jailDiceThrows = value; }
		}

		public bool IsInJail
		{
			get { return isInJail; }
			set { isInJail = value; }
		}

		public int Position
		{
			get { return position; }
            set { if (value > 39) value = value - 39; position = value; }
		}
		public bool Turn { get { return turn; } set { turn = value; } }
		public int One { get { return one; } set { one = value; } }
		public int Five { get { return five; } set { five = value; } }
		public int Ten { get { return ten; } set { ten = value; } }
		public int Twenty { get { return twenty; } set { twenty = value; } }
		public int Fifty { get { return fifty; } set { fifty = value; } }
		public int Hunderd { get { return hunderd; } set { hunderd = value; } }
		public int Fivehunderd { get { return fivehunderd; } set { fivehunderd = value; } }
		public Color Color { get { return color; } set { color = value; } }
		#endregion
	}

}
